<?php
namespace WebApper;
/*
 * [emailimport]
 *
 */
class UserPayment extends  \WebApper\Shortcode {
	/**
     * Define shortcode properties
     *
     */
	protected $shortcode = 'userPayment';
	
	/**
     * Initialize the Shortcode Class
     *
     */
	public function __construct() {
		add_shortcode( $this->shortcode, array($this, 'shortcode') );
		add_action( 'wp_ajax_web_apper' . $this->shortcode, array($this, 'sendAjaxResponse') );
		add_action( 'wp_ajax_nopriv_web_apper' . $this->shortcode, array($this, 'sendAjaxResponse') );	
				
		/*if ( ! wp_next_scheduled( 'my_daily_email_import' ) )
		{
			wp_schedule_event( time() , 'every5mins', 'my_daily_email_import');			
		}	
		add_action( 'my_daily_email_import', array($this, 'shortcode') );*/	
	}

    /**
     * Handles the add post shortcode
     *
     * @param array $atts
     */
    public function shortcode( $atts ) {
		global $wpdb, $webapper;
		 $user_payment_transaction = $webapper->tables->user_payment_transaction; 
		 $user_id= get_current_user_id(); 
		
		// Check for required shortcode attributes
		$msg = $this->has_req_attrs( $atts );
		if ( $msg !== true )
			return $msg;	
				
?>

<?php				
				
						
		    $get_user_meta      = get_user_meta($user_id);
		    $payment_master = web_apper_get_payment_master($user_id);
	        $user_payment_master_id = $payment_master ->user_payment_master_id;
			$card_holderName    	= $payment_master ->card_holder_name;
			list($fname, $lname) = explode(' ',$card_holderName,2);
			$card_type         	    = $payment_master ->card_type;
			$card_number        	= $payment_master ->card_number;
			$cardExpire_month   	= $payment_master ->card_expiration_month;
			$cardExpire_year   	    = $payment_master ->card_expiration_year;
			$year                   =substr($cardExpire_year,2);
		    $date 				    = $cardExpire_month.$year;
			$country            	= $payment_master ->card_country;
			$address            	= $payment_master ->card_address;
			$city               	= $payment_master ->card_city;
			$state              	= $payment_master ->card_state;
			$card_ccv           	= $payment_master ->card_ccv;
			$zip_code  				= $payment_master ->card_zip_code;
			$bank_routing_number	= $payment_master ->bank_routing_number;
			$account_number 		= $payment_master ->bank_account_number;
			$check_number 			= $payment_master ->bank_check_number; 
		
		
		$post_url = AUTHORIZED_NET_URL;
		$post_values = array(
			
			// the API Login ID and Transaction Key must be replaced with valid values
			"x_login"			=> AUTHORIZED_NET_LOGIN,
			"x_tran_key"		=> AUTHORIZED_NET_TRAN_KEY,
		    "x_version"			=> "3.1",
			"x_delim_data"		=> "TRUE",
			"x_delim_char"		=> "|",
			"x_relay_response"	=> "FALSE",
		    "x_type"			=> "AUTH_CAPTURE",
			"x_method"			=> "CC",
			"x_card_num"		=> $card_number,
			"x_exp_date"		=> $date,
		    "x_amount"			=> "30.99",
			"x_description"		=> "A Sample Transaction",
		    "x_first_name"		=> $fname,
			"x_last_name"		=> $lname,
			"x_country"	        => $country,
			"x_address"			=> $address,
			"x_city"			=> $city,
			"x_state"			=> $state,
			"x_zip"				=> $zip_code
			// Additional fields can be added here as outlined in the AIM integration
			// guide at: http://developer.authorize.net
		);
		$data = GetUrlValue($post_values, $post_url );
		//print_r($data);
		echo "<table>";
		foreach($data as $dataRow)
		{
			echo "<tr>";
			for($i=0;$i<=67;$i++)
			{
				echo "<td>".$dataRow[$i]."</td>";
				
			}
			echo "</tr>";
		}
		echo "</table>";
		
		
		$sql = $wpdb->prepare( "INSERT INTO {$user_payment_transaction} ( user_id,amount_paid ) VALUES ( %d,%f)", $user_id, '70.99' ) ;
     $result = $wpdb->query( $sql );
	 if($result)
	 {
		 echo "The Transcatoin Successfully done";
	 }
	
	 		
		
	}
}

$initialize = new UserPayment(); 
?>